/*
 * Copyright:  2018 smarabbit studio.
 *
 *  Licensed under the Confluent Community License; you may not use this file
 *  except in compliance with the License.  You may obtain a copy of the License at
 *
 *  http://www.confluent.io/confluent-community-license
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations under the License.
 *
 *  @作   者： 黄开晖 (117227773@qq.com)
 *  @日   期:  2021年7月7日
 */
package com.massyframework.beanskin.web.context;

import java.util.Objects;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * ServletContextListener代理
 * @author huangkh
 *
 */
public class ServletContextListenerDelegate implements ServletContextListener {
	
	private ServletContext servletContext;
	private ServletContextListener listener;
	
	/**
	 * 构造方法
	 * @param context {@link ServletContext}
	 * @param listener {@lnk ServletContextListener}
	 */
	public ServletContextListenerDelegate(ServletContext context, ServletContextListener listener) {
		this.servletContext = Objects.requireNonNull(context, "\"context\" cannot be null.");
		this.listener = Objects.requireNonNull(listener, "\"listener\" cannot be null.");
	}

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		this.listener.contextInitialized(new ServletContextEvent(servletContext));
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		this.listener.contextDestroyed(new ServletContextEvent(servletContext));
	}

	public ServletContext getServletContext() {
		return this.servletContext;
	}
	
	public ServletContextListener getServletContextListener() {
		return this.listener;
	}

}
